<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">文件编号</label>
        <el-input v-model="query.wjbh" clearable placeholder="文件编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">文件文号</label>
        <el-input v-model="query.wjwh" clearable placeholder="文件文号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">标题</label>
        <el-input v-model="query.bt" clearable placeholder="标题" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="文件编号" prop="wjbh">
            <el-input v-model="form.wjbh" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="文件文号" prop="wjwh">
            <el-input v-model="form.wjwh" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="标题" prop="bt">
            <el-input v-model="form.bt" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主题词">
            <el-input v-model="form.ztc" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="密级码">
            <el-input v-model="form.mjm" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="紧急程度码">
            <el-input v-model="form.jjcdm" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="页数">
            <el-input v-model="form.ys" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="文件分类码">
            <el-input v-model="form.wjflm" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="正文">
            <el-input v-model="form.zw" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="附件">
            <el-input v-model="form.fj" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发文日期">
            <el-input v-model="form.fwrq" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="抄送单位">
            <el-input v-model="form.csdw" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="wjbh" label="文件编号" />
        <el-table-column prop="wjwh" label="文件文号" />
        <el-table-column prop="bt" label="标题" />
        <el-table-column prop="ztc" label="主题词" />
        <el-table-column prop="mjm" label="密级码" />
        <el-table-column prop="jjcdm" label="紧急程度码" />
        <el-table-column prop="ys" label="页数" />
        <el-table-column prop="wjflm" label="文件分类码" />
        <el-table-column prop="zw" label="正文" />
        <el-table-column prop="fj" label="附件" />
        <el-table-column prop="fwrq" label="发文日期" />
        <el-table-column prop="csdw" label="抄送单位" />
        <el-table-column v-if="checkPer(['admin','wjjbxx:edit','wjjbxx:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudWjjbxx from '@/api/wjjbxx'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { columnId: null, wjbh: null, wjwh: null, bt: null, ztc: null, mjm: null, jjcdm: null, ys: null, wjflm: null, zw: null, fj: null, fwrq: null, csdw: null }
export default {
  name: 'Wjjbxx',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '文件基本信息', url: 'api/wjjbxx', idField: 'columnId', sort: 'columnId,desc', crudMethod: { ...crudWjjbxx }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'wjjbxx:add'],
        edit: ['admin', 'wjjbxx:edit'],
        del: ['admin', 'wjjbxx:del']
      },
      rules: {
        wjbh: [
          { required: true, message: '文件编号不能为空', trigger: 'blur' }
        ],
        wjwh: [
          { required: true, message: '文件文号不能为空', trigger: 'blur' }
        ],
        bt: [
          { required: true, message: '标题不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'wjbh', display_name: '文件编号' },
        { key: 'wjwh', display_name: '文件文号' },
        { key: 'bt', display_name: '标题' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
